//
//  ZH_HotRecommendeCollectionViewCell.m
//  WisdomStar
//
//  Created by zhangliwen on 2018/10/19.
//  Copyright © 2018年 zhangliwen. All rights reserved.
//

#import "ZH_HotRecommendeCollectionViewCell.h"
@interface ZH_HotRecommendeCollectionViewCell()
///图标
@property (nonatomic, weak) UIImageView *iconImageView;
///标题
@property (nonatomic, weak) UILabel *titleLabel;
//价格
@property (nonatomic,weak)UILabel *priceLabel;
@end
@implementation ZH_HotRecommendeCollectionViewCell
///注册cell
+(void)registerCollectionView:(UICollectionView*)collectionView
{
    [collectionView registerClass:[ZH_HotRecommendeCollectionViewCell class] forCellWithReuseIdentifier:@"ZH_HotRecommendeCollectionViewCell"];
}

///创建
+(id)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath
{
    return [collectionView dequeueReusableCellWithReuseIdentifier:@"ZH_HotRecommendeCollectionViewCell" forIndexPath:indexPath];
}
///加载子视图约束
-(void)loadSubviewConstraints
{
    [self.iconImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.equalTo(self.contentView).offset(FITSCALE(0));
        make.left.right.equalTo(self.contentView);
        make.height.mas_equalTo(FITSCALE(163));
    }];
    [self.titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.contentView).offset(FITSCALE(11));
        make.right.equalTo(self.contentView).offset(FITSCALE(-11));
        make.top.equalTo(self.iconImageView.mas_bottom).offset(FITSCALE(10));
        make.height.mas_equalTo(FITSCALE(13));
    }];
    [self.priceLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.titleLabel);
        make.top.equalTo(self.titleLabel.mas_bottom).offset(FITSCALE(8));
        make.height.mas_equalTo(FITSCALE(13));
    }];
    
}
- (void)updataUI:(NSMutableDictionary *)data{
    if (data) {
        [self.iconImageView sd_setImageWithURL:[NSURL URLWithString:[NSString stringWithFormat:@"%@%@",SERVER_TEST,data[@"cover_img"]]] placeholderImage:nil];
        self.titleLabel.text = data[@"name"];
        self.priceLabel.text = [NSString stringWithFormat:@"￥%@",data[@"show_price"]];
    }
}
#pragma mark - getter,setter
- (UIImageView *)iconImageView
{
    if(!_iconImageView){
        UIImageView *image = [UIImageView createImageViewWithName:@""];
//        image.backgroundColor = [UIColor redColor];
        image.contentMode = UIViewContentModeScaleToFill;
        image.clipsToBounds = YES;
        [self.contentView addSubview:_iconImageView = image];
    }
    return _iconImageView;
}
- (UILabel *)titleLabel
{
    if(!_titleLabel){
        UILabel *label = [UILabel createLabelWithText:@"商品名称" font:kFontSize_26];
        //        label.textColor = [UIColor colorWithHexString:@"#5C5C5C"];
//        [label setTextAlignment:NSTextAlignmentCenter];
        [self.contentView addSubview:_titleLabel = label];
    }
    return _titleLabel;
}
- (UILabel *)priceLabel{
    if (!_priceLabel) {
        UILabel *label = [UILabel createLabelWithText:@"￥100" font:kFontSize_26];
        label.textColor = [UIColor colorWithHexString:@"#F0302F"];
        [self.contentView addSubview:_priceLabel = label];
    }
    return _priceLabel;
}
@end
